package nursestation;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import bedside.Alarm;

import common.CentralInterface;

public class Central implements CentralInterface {

	
	
	@Override
	public void alarmReset(Alarm alarm) throws RemoteException {
		System.out.println("Alarm: " + alarm.getMyID() + " has been reset.");

	}

	@Override
	public void alarmTriggered(Alarm alarm) throws RemoteException {
		System.out.println("Alarm: " + alarm.getMyID() + " has been triggered.");

	}

	@Override
	public void callButtonReset() throws RemoteException {
		System.out.println("Call Button reset.");

	}

	@Override
	public void callRequest() throws RemoteException {
		System.out.println("Call Button Triggered.");

	}
	
	public static void main( String[] args ) {
//		if (System.getSecurityManager() == null) {
//            System.setSecurityManager(new SecurityManager());
//        }
        try {
            String name = "Central Station";
            CentralInterface central = new Central();
            CentralInterface stub =
                (CentralInterface) UnicastRemoteObject.exportObject(central, 0);
            Registry registry = LocateRegistry.getRegistry();
            registry.rebind(name, stub);
            System.out.println("Central Station bound"); 
        } catch (Exception e) {
            System.err.println("Central Station exception:");
            e.printStackTrace();
        }

	}

}
